﻿<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" MasterPageFile="~/Views/Shared/Site.Master" %>

<asp:Content runat="server" ID="PageTitle" ContentPlaceHolderID="PageTitle">
    <title>工作任务</title>
</asp:Content>
<asp:Content runat="server" ID="Content1" ContentPlaceHolderID="PageStyles">
    <link href="../../Content/project/project.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/project/project.workitemlist.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/ui.button.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/table_jui.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .text
        {
            width: 200px;
        }
        
        .hours
        {
            width: 60px;
        }
        .txtprojectName
        {
            color: #aaa;
        }
        .dataTables_wrapper
        {
            min-height: 50px;
        }
    </style>
</asp:Content>
<asp:Content runat="server" ID="PageScripts" ContentPlaceHolderID="PageScripts">
    <script src="../../Scripts/jquery.dataTables.js" type="text/javascript"></script>
    <script type="text/javascript">
        //************* URL常量
        
        var TableMapping= {
            finishedMap: [" ", "内容-计划-项目", "完成时间", "负责人"],
            unfinishedMap: [" ", "内容-计划-项目", "到期","负责人", "操作"],
            finishenTitle: '已经完成的工作任务',
            unfinishedTitle:'进行中的工作任务'
        };

        var isLoading = true;

        var filterArgs,baseArgs;

        filterArgs = baseArgs =  {
            isFinish:false,
            onlyMine:false,
            onlyMyAssign:false,
        };
        
        var args = {
            myConvertor: TableMapping.unfinishedMap,
            GetWorkitemListService:function(callback){  
                EzDesk.Service.GetWorkItems_Sync(
                    callback,
                    filterArgs
                );
            }
        };


        function refreshWorkitemListArgs(isFinished) {
            if(isFinished){
                args.myConvertor = TableMapping.finishedMap;
                $('#title-workitem-list').html(TableMapping.finishenTitle);    
            }else {
                $('#title-workitem-list').html(TableMapping.unfinishedTitle);
                args.myConvertor = TableMapping.unfinishedMap;
            }
            
        }
        
        
        function refreshWorkitemListByFilter(e) {
            filterArgs = $.extend({},baseArgs, e);
            
            if (filterArgs.isFinish == "true") {
                refreshWorkitemListArgs(true);
            } else {
                refreshWorkitemListArgs(false);
            }

            $('#divWorkitems').workitemList(args);
        }

        
        
        function refreshWorkitemListToFinishedStatus() {
            //projectId = null, isMine = false, isFinished = true
            WorkItemFilter.InitSelector(null, false, true);

            refreshWorkitemListArgs(true);

            $.extend(filterArgs,{isFinish:true});

            $('#divWorkitems').workitemList(args);
        }

        
        
        function initFilterControl() {
            $('#tip_workitemFilter').eztips();

            WorkItemFilter.Init();            
            WorkItemFilter.InitSelector(null, false, false);
            WorkItemFilter.InitCallBack(function (e) {
                if (isLoading) {                
                    isLoading = false;
                    var workitemId = $.getQueryString('workitemId');
                    var isFinished = $.getQueryString('isFinished');

                    if (workitemId && isFinished == 'true') {
                        refreshWorkitemListToFinishedStatus();
                    }else{
                        refreshWorkitemListByFilter(e);
                    }

                    //highlight
                    $('#divWorkitems').workitemList('Highlight', workitemId, { action: 'stay'});

                } else {
                    refreshWorkitemListByFilter(e);

                }
            });
        };

        
        
        function doCreateWorkitem() {
            if (WorkitemCreatorSimple) {
                WorkitemCreatorSimple.Show(true, null);
                WorkitemCreatorSimple.SubmitSuccessCallback = function (workitemId) {
                    //projectId = null, isMine = false, isFinished = false
                    WorkItemFilter.InitSelector(null, false, false);

                    refreshWorkitemListArgs(false);
                    
                    filterArgs = baseArgs;

                    $('#divWorkitems').workitemList(args);
                    $('#divWorkitems').workitemList('Highlight', workitemId);
                };
            }
        };

      

        //初始化页面
        function initPage() {
            initFilterControl();
        };

        //初始化事件
        function initPageEvent() {
            $('#btn-add-workitem').click(function () {
                doCreateWorkitem();
            });
        };

        $(function () {
            initPage();
            initPageEvent();
        });

    </script>
</asp:Content>
<asp:Content runat="server" ID="PageHead" ContentPlaceHolderID="PageHead">
    <%
        Html.RenderPartial("_sayHello"); %>
</asp:Content>
<asp:Content runat="server" ID="Page" ContentPlaceHolderID="PageContent">
    <div id="page-head" class="page-head">
        <img src="../../Content/icons/workitems.png" style="width: 48px; height: 48px;" alt="add" />
        <span class="title">工作任务</span>
    </div>
    <div id="page-body">
        <div class="content">
            <div class="content-section content-section">
                <div id="div-add-workitem" style="float: right;">
                    <div id="btn-add-workitem">
                        添加工作任务</div>
                    <script type="text/javascript">
                        $(function () {
                            $("#btn-add-workitem").button({
                                icons: {
                                    primary: "ui-icon-circle-plus"
                                },
                                text: true
                            });
                        });
                    </script>
                </div>
                <p id="title-workitem-list" style="line-height: 35px; font-weight: bold;">
                </p>
                <div id="divWorkitems" class="tableContainer">
                </div>
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content runat="server" ID="PageShortcut" ContentPlaceHolderID="PageShortcut">
</asp:Content>
<asp:Content runat="server" ID="PageFoot" ContentPlaceHolderID="PageFoot">
    <div>
        <% Html.RenderPartial("_workitemCreatorSimple"); %>
        <script>
            $(function () {
                var pageAction = location.hash;
                if (pageAction == "#create") {
                    doCreateWorkitem();
                }
            });
        </script>
    </div>
    <div id="tip_workitemFilter" style="display: none;">
        <% Html.RenderPartial("_workitemFilter"); %>
    </div>
</asp:Content>
